import { TreeSelect } from "antd";
import { useEffect, useState } from "react";
import { useForm } from "../../../framework/common/context/metadata-context";

export default function (props) {
  const { data: tplData } = useForm().root;
  const [treeData, setTreeData] = useState([]);
  useEffect(() => {
    const arrayToTree = (arr, parent = "") => arr.filter((item) => item.parent === parent).map((child) => ({ title: child.text, value: child.id, children: arrayToTree(arr, child.id) }));
    setTreeData(arrayToTree(tplData?.DefaultApproveGuide?.SaveFolder?.SaveFolderList || []));
  }, []);
  return <TreeSelect {...props} treeData={treeData}></TreeSelect>;
}
